package IC.lir.operands;
import IC.lir.*;

/**
 * A register operand (R1, R2, Rdummy)
 * 
 */
public class RegOperand extends Operand implements LoweringContext {
	private int 			count;
	public static int 		AllCounter = 0;

	/** dummy register */
	private static RegOperand RegDummy = new RegOperand(-1);
	
	/**
	 * create a new register
	 */
	public RegOperand() {
		this.count = AllCounter++;
	}
	
	/**
	 * reset the general counter to 0
	 */
	public static void resetCounter() {
		AllCounter = 0;
	}
	
	/** 
	 * to create the dummy register
	 * @param num the number of the register
	 */
	private RegOperand(int num) {
		this.count = num;
	}

	/**
	 * @return the register index
	 */
	public int getNum() {
		return count;
	}

	/**
	 * @return the static register counter
	 */
	public static int getAllCount() {
		return AllCounter;
	}
	
	public static RegOperand getDummy() {
		return RegDummy;
	}

	public String toString() {
		return (count==-1)?"Rdummy":"R"+count;
	}
	
	@Override
	public int getPrio() {
		return count+1;
	}
	
	public ContextKind getKind() {
		return ContextKind.REG;
	}
	
	public int hashCode() {
		return (count+1)^toString().hashCode();
	}
	
	public boolean equals(Object o) {
		if(o instanceof RegOperand) {
			return ((RegOperand)o).getNum() == count;
		}
		return false;
	}
}
